home *** CD-ROM | disk | FTP | other *** search
- {
- procedure and functions in this library
-
- WriteStr write message out at (Col,Line)
- Error writes message out at (1,1), waits for character
- GetChar prompt user for one of a set of characters
- Yes asks user questions, waits for a Y/N answer
- GetInteger prompt user for an integer value in the range Min..Max
- GrabInt function version of GetInteger; used for subrange vars
- WriteReal write real value w/adjustable format
- GetReal prompt user for a real value in the range Min..Max
- GetString prompt user for a string
- IOCheck checks for I/O error; prints message if necessary
-
- }
-
- type
- MsgStr = string[80];
- CharSet = set of Char;
-
- var
- IOErr : Boolean;
- IOCode : Integer;
-
- procedure WriteStr(Col,Line : Integer; TStr : MsgStr);
- {
- purpose writes message out at spot indicated
- last update 23 Jun 85
- }
- begin
- GoToXY(Col,Line); ClrEol;
- Write(TStr)
- end; { of proc WriteStr }
-
- procedure Error(Msg : MsgStr);
- {
- purpose writes error message out at (1,1); waits for character
- last update 05 Jul 85
- }
- const
- Bell = ^G;
- var
- Ch : Char;
- begin
- WriteStr(1,1,Msg+Bell+' (hit any key) ');
- Read(Kbd,Ch)
- end; { of proc Error }
-
- procedure GetChar(var Ch : Char; Prompt : MsgStr; OKSet : CharSet);
- {
- purpose let user enter command
- last update 23 Jun 85
- }
- begin
- WriteStr(1,1,Prompt);
- repeat
- Read(Kbd,Ch);
- Ch := UpCase(Ch)
- until Ch in OKSet;
- WriteLn(Ch)
- end; { of proc GetChar }
-
- function Yes(Question : MsgStr) : Boolean;
- {
- purpose asks user Y/N question
- last update 03 Jul 85
- }
- var
- Ch : Char;
- begin
- GetChar(Ch,Question+' (Y/N) ',['Y','N']);
- Yes := (Ch = 'Y')
- end; { of func Yes }
-
- function GrabInt(Prompt : MsgStr; Min,Max : Integer) : Integer;
- {
- purpose prompts user for value in range Min..Max
- note you may not be able to pass subrange variables to
- GetInteger because of the difference in size. In
- such cases, you can use GrabInt and directly assign
- the returned value to the subrange variable.
- last update 05 Jul 85
- }
- var
- Val : Integer;
- begin
- {$I-}
- if Min > Max then begin
- Val := Min;
- Min := Max;
- Max := Val
- end;
- repeat
- WriteStr(1,1,Prompt);
- Write(' [',Min,'..',Max,']: ');
- ReadLn(Val)
- until (IOResult = 0) and (Min <= Val) and (Val <= Max);
- GrabInt := Val
- {$I+}
- end; { of proc GetInteger }
-
- procedure GetInteger(var Val : Integer; Prompt : MsgStr; Min,Max : Integer);
- {
- purpose prompts user for value in range Min..Max
- last update 22 June 1985
- }
- begin
- Val := GrabInt(Prompt,Min,Max)
- end; { of proc GetInteger }
-
- procedure WriteReal(RVal : Real; Width,Digits : Byte);
- {
- purpose decide which format to use based on magnitude
- last update 10 Jul 85
- }
- const
- Ln10 = 2.302585093;
- var
- TVal : Real;
- Limit,Log : Integer;
-
- procedure Condition(Min : Byte; var Val :Byte; Max : Byte);
- begin
- if Val < Min
- then Val := Min
- else if Val > Max
- then Val := Max
- end; { of local proc Condition }
-
- begin
- Condition(8,Width,80);
- Condition(0,Digits,Width-3);
- TVal := Abs(RVal);
- Limit := (Width-Digits) - 1;
- if RVal < 0.0
- then Limit:= Limit - 1;
- if TVal = 0.0
- then Log := 0
- else Log := Round(Ln(TVal)/Ln10);
- if (Log < -Digits) or (Log >= Limit)
- then Write(RVal:Width)
- else Write(RVal:Width:Digits)
- end; { of proc WriteReal }
-
- procedure GetReal(var Val : Real; Prompt : MsgStr; Min,Max : Real);
- {
- purpose prompts user for value in range Min..Max
- last update 23 June 85
- }
- begin
- {$I-}
- repeat
- WriteStr(1,1,Prompt+' [');
- WriteReal(Min,8,4); Write('..'); WriteReal(Max,8,4);
- Write(']: '); ReadLn(Val);
- until (IOResult = 0) and (Min <= Val) and (Val <= Max)
- {$I+}
- end; { of proc GetReal }
-
- procedure GetString(var NStr : MsgStr; Prompt : MsgStr; MaxLen : Integer;
- OKSet : CharSet);
- {
- purpose get string from user
- last update 09 Jul 85
- }
- const
- BS = ^H;
- CR = ^M;
- ConSet : CharSet = [BS,CR];
- var
- TStr : MsgStr;
- TLen,X : Integer;
- Ch : Char;
- begin
- {$I-} { turn off I/O checking }
- TStr := '';
- TLen := 0;
- WriteStr(1,1,Prompt);
- X := 1 + Length(Prompt);
- OKSet := OKSet + ConSet;
- repeat
- GoToXY(X,1);
- repeat
- Read(Kbd,Ch)
- until Ch in OKSet;
- if Ch = BS then begin
- if TLen > 0 then begin
- TLen := TLen - 1;
- X := X - 1;
- GoToXY(X,1); Write(' ');
- end
- end
- else if (Ch <> CR) and (TLen < MaxLen) then begin
- Write(Ch);
- TLen := TLen + 1;
- TStr[TLen] := Ch;
- X := X + 1;
- end
- until Ch = CR;
- if TLen > 0 then begin
- TStr[0] := Chr(TLen);
- NStr := TStr
- end
- else Write(NStr)
- {$I+}
- end; { of proc GetString }
-
- procedure IOCheck;
- {
- purpose check for IO error; print message if needed
- last update 08 Jul 85
- }
- var
- TStr : string[4];
- begin
- IOCode := IOResult;
- IOErr := (IOCode <> 0);
- if IOErr then case IOCode of
- $01 : Error('IOERROR> File does not exist');
- $02 : Error('IOERROR> File not open for input');
- $03 : Error('IOERROR> File not open for output');
- $04 : Error('IOERROR> File not open');
- $10 : Error('IOERROR> Error in numeric format');
- $20 : Error('IOERROR> Operation not allowed on logical device');
- $21 : Error('IOERROR> Not allowed in direct mode');
- $22 : Error('IOERROR> Assign to standard files not allowed');
- $90 : Error('IOERROR> Record length mismatch');
- $91 : Error('IOERROR> Seek beyond end of file');
- $99 : Error('IOERROR> Unexpected end of file');
- $F0 : Error('IOERROR> Disk write error');
- $F1 : Error('IOERROR> Directory is full');
- $F2 : Error('IOERROR> File size overflow');
- $FF : Error('IOERROR> File disappeared')
- else Str(IOCode:3,TStr);
- Error('IOERROR> Unknown I/O error: '+TStr)
- end
- end; { of proc IOCheck }
-
-